﻿using System.Windows.Controls;
using LogInModule.ViewModels;

namespace LogInModule.Views
{
    public partial class UserLogInView : UserControl
    {
        public UserLogInView(UserLogInViewModel userLogInViewModel)
        {
            InitializeComponent();
            this.DataContext = userLogInViewModel;

            this.LogInToRegister.Click += (s, e) =>
                {
                    userLogInViewModel.CleanForm();
                    this.LoginPanel.Visibility = System.Windows.Visibility.Collapsed;
                    this.RegisterPanel.Visibility = System.Windows.Visibility.Visible;
                };

            this.RegisterToLogIn.Click += (s, e) =>
                {
                    userLogInViewModel.CleanForm();
                    this.RegisterPanel.Visibility = System.Windows.Visibility.Collapsed;
                    this.LoginPanel.Visibility = System.Windows.Visibility.Visible;
                };

            this.EditToLogIn.Click += (s, e) =>
                {
                    userLogInViewModel.CleanForm();
                    this.EditPanel.Visibility = System.Windows.Visibility.Collapsed;
                    this.LoginPanel.Visibility = System.Windows.Visibility.Visible;
                };

            this.LogInToEdit.Click += (s, e) =>
                {
                    if (userLogInViewModel.InitializeProfileInformation())
                    {
                        this.LoginPanel.Visibility = System.Windows.Visibility.Collapsed;
                        this.EditPanel.Visibility = System.Windows.Visibility.Visible;
                    }
                };

            this.LogInPassword.KeyDown += (s, e) =>
                {
                    if (e.Key == System.Windows.Input.Key.Enter)
                    {
                        userLogInViewModel.Password = this.LogInPassword.Password;
                        this.LoginButton.Command.Execute(null);
                    }
                };
        }
    }
}